package com.demo.java.model.params;

import com.demo.java.model.enums.ErrorCode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Res {
    private int code;
    private Object data;
    private String msg;

    public Res(ErrorCode errorCode) {
        this(errorCode, null);
    }

    public Res(ErrorCode errorCode, Object data) {
        this.code = errorCode.getCode();
        this.msg = errorCode.getName();
        this.data = data;
    }

    public static Res ok() {
        return new Res(ErrorCode.SUCCESS);
    }

    public static Res ok(Object data) {
        return new Res(ErrorCode.SUCCESS, data);
    }

    public static Res ok(ErrorCode errorCode, Object data) {
        return new Res(errorCode, data);
    }

    public static Res fail() {
        return new Res(ErrorCode.FAILED);
    }

    public static Res fail(Object data) {
        return new Res(ErrorCode.FAILED, data);
    }

    public static Res fail(ErrorCode errorCode, Object data) {
        return new Res(errorCode, data);
    }
}
